package com.sali.model;

import com.sali.rule.Rule;
import lombok.Data;

import java.util.List;

/**
 * @description:
 * @author: sali
 * @date: 2024/7/16 20:54.
 * @version: 1.0
 */
@Data
public abstract class BaseFieldRule {


    private Field field;
    private List<Rule> rules;

    /**
     * 判断字段是否需要处理，如果来源字段为空是不需要处理的
     *
     * @return
     */
    public abstract boolean isHandle();

    /**
     * 获取来源字段
     *
     * @return
     */
    public abstract List<String> getSrcFields();

    /**
     * 获取来源索引
     *
     * @return
     */
    public abstract List<String> getSrcIndex();

    /**
     * 根据规则进行解析
     *
     * @param value 待转换数据
     * @return
     */
    public Object parseRules(Object value) {
        List<Rule> rules = this.rules;
        if (rules == null || rules.isEmpty()) {
            return value;
        }

        Object temp = null;
        for (Rule rule : rules) {
            temp = rule.invoke(value);
            value = temp;
        }
        return temp;
    }


}
